package com.oyjd.ybx.business.age.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.oyjd.ybx.bean.po.AgeType;
import com.oyjd.ybx.bean.vo.AgeTypeVO;
import com.oyjd.ybx.business.age.dao.ageDao;
import com.oyjd.ybx.business.age.service.ageService;
import com.oyjd.ybx.fw.action.Page;

/**
 * 
 * 年龄段分类业务接口实现
 * 
 * @author <b>欧建东<br/>
 *         Email:oyjd@163.com</b>
 * @version 1.0
 */
@Component
@Transactional(readOnly = true)
public class ageServiceImpl implements ageService {
	private ageDao dao;

	@Autowired
	public void setDao(ageDao dao) {
		this.dao = dao;
	}

	/**
	 * 获取年龄段分类列表数据
	 * 
	 * @param page
	 *            页面对象
	 * @return
	 */
	public Page<AgeTypeVO> getList(Page<AgeTypeVO> page) {
		return dao.getList(page);
	}

	/**
	 * 根据ID获取年龄段分类对象信息
	 * 
	 * @param id
	 *            ID
	 * @return
	 */
	public AgeTypeVO getAgeTypeVO(String ageId) {
		return dao.getAgeTypeVO(ageId);
	}

	/**
	 * 增加年龄段分类
	 * 
	 * @param ageId
	 *            年龄段ID
	 * @param ageArea
	 *            年龄段
	 * @param ageNote
	 *            年龄段描述
	 * @throws Exception
	 */
	@Transactional(readOnly = false)
	public void add(String ageArea, String ageNote) throws Exception {
		AgeType ageType = new AgeType();
		ageType.setAgeArea(ageArea);
		ageType.setAgeNote(ageNote);
		ageType.setOrderKey(System.currentTimeMillis());
		dao.create(ageType);
	}

	/**
	 * 修改年龄段分类
	 * 
	 * @param ageId
	 *            年龄段ID
	 * @param ageArea
	 *            年龄段
	 * @param ageNote
	 *            年龄段描述
	 * @throws Exception
	 */
	@Transactional(readOnly = false)
	public void edit(String ageId, String ageArea, String ageNote) throws Exception {
		AgeType ageType = (AgeType) dao.queryById(AgeType.class, ageId);
		ageType.setAgeId(ageId);
		ageType.setAgeArea(ageArea);
		ageType.setAgeNote(ageNote);
		dao.update(ageType);
		//

	}

	/**
	 * 删除年龄段分类
	 * 
	 * @param ids
	 *            多个ID
	 * @return
	 */
	@Transactional(readOnly = false)
	public void remove(String[] ids) {
		dao.remove(ids);
	}

}
